#ifndef MVDMAINWINDOW_H
#define MVDMAINWINDOW_H

#include <QWidget>
#include <QStringListModel>
#include <QSqlTableModel>//数据库模型,表视图
#include <QItemDelegate>//代理
#include <QComboBox>//下拉
#include <QDateEdit>//日历
#include <QDate>
#include <QObject>
#include <QPushButton>
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include "devicemap.h"

//自定义下拉列表
//代理:使得表格视图里面的框子,可以显示其他组件
class CustomDelegate : public QItemDelegate
{
    Q_OBJECT
public:
    //构造
    CustomDelegate(QObject* parent = Q_NULLPTR):QItemDelegate(parent){}

    //override关键字: 意思是重写了这个函数
    //创建代理组件 QComBox下拉列表
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        Q_UNUSED(index);
        QComboBox * genderBox = new QComboBox(parent);
        return genderBox;
    }
    //修改comobox的内容
    void setEditorData(QWidget *editor, const QModelIndex &index) const override
    {
        QComboBox *genderBox = static_cast<QComboBox *>(editor);
        genderBox->addItems(QStringList()<<"PM2.5"<<"PM10"<<"AQI"<<"噪音"<<"气温"<<"温度"<<"风速"<<"污水池PH值"<<"用电量"<<"用水量");
    }
    //获取修改后的内容并修改经model
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
    {
        QComboBox* genderBox = static_cast<QComboBox*>(editor);
        QString gender = genderBox->currentText();
        model->setData(index,QVariant(gender));
    }
    //设定存放位置
    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        editor->setGeometry(option.rect);
    }
};

//自定义下拉列表
//代理:使得表格视图里面的框子,可以显示其他组件
class CustomDelegate_2 : public QItemDelegate
{
    Q_OBJECT
public:
    //构造
    CustomDelegate_2(QObject* parent = Q_NULLPTR):QItemDelegate(parent){}

    //override关键字: 意思是重写了这个函数
    //创建代理组件 QComBox下拉列表
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        Q_UNUSED(index);
        QComboBox * genderBox = new QComboBox(parent);
        return genderBox;
    }
    //修改comobox的内容
    void setEditorData(QWidget *editor, const QModelIndex &index) const override
    {
        QComboBox *genderBox = static_cast<QComboBox *>(editor);
        genderBox->addItems(QStringList()<<"生活区"<<"工作区"<<"施工区");
    }
    //获取修改后的内容并修改经model
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
    {
        //接收指针
        QComboBox* genderBox = static_cast<QComboBox*>(editor);
        QString gender = genderBox->currentText();
        model->setData(index,QVariant(gender));
    }
    //设定存放位置
    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        editor->setGeometry(option.rect);
    }
};



namespace Ui {
class MVDMainWindow;
}

class MVDMainWindow : public QWidget
{
    Q_OBJECT

public:
    explicit MVDMainWindow(QWidget *parent = 0);
    ~MVDMainWindow();
    void testModelViem();
    QSqlTableModel* t_model;
    void initView();
    void refress();
private slots:
    void on_addbtn_clicked();

    void on_pushButton_9_clicked();

    void on_pushButton_10_clicked();

    void on_pushButton_11_clicked();

    void on_pushButton_clicked();

    void getLocation(int row,int x,int y);

    void on_pushButton_13_clicked();

private:
    Ui::MVDMainWindow *ui;
};

#endif // MVDMAINWINDOW_H
